/**
 * add record to a domain
 */
export default defineEventHandler(async (event) => {
  const name = getRouterParam(event, 'name')
  const uuid = getRouterParam(event, 'uuid')
  const data = await useStorage().getItem<Domain>(`first:domain:${name}`)
  if (data === null) {
    // TODO: error handle.
    return 'emm'
  }
  const records = data.records || []
  console.log('server side add record', records)
  const newRecords = records.filter((r) => r.uuid !== uuid)
  data.records = newRecords
  await useStorage().setItem(`first:domain:${name}`, data)
  return 'success'
})
